package com.hundsun.yr.universal.p2p.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.Utils.HeaderMap;
import com.hundsun.yr.universal.library.base.BaseAppManager;
import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog;
import com.hundsun.yr.universal.p2p.bean.AuthListBean;
import com.hundsun.yr.universal.p2p.bean.BankAccountBeen;
import com.hundsun.yr.universal.p2p.bean.ManeBean;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.Extras;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.presenter.impl.InitializePresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.view.base.InitializeView;

import org.json.JSONObject;

import java.util.HashMap;

public class ManagementActivity extends BaseActivity implements View.OnClickListener,
        HSDialog.HSDialogOnItemClickListener,
        InitializeView {
    /**
     * 请求
     **/
    private RequestPresenter mPresenter = null;

    /**
     * 网络请求
     */
    private RequestPresenter mPresenter2 = null;
    /**
     * 实名认证
     */
    private RelativeLayout Rl_name;
    private TextView real_name;
    /**
     * 交易密码
     */
    private RelativeLayout Rl_psd;
    private TextView tv_set_psd;

    /**
     * 缴费授权
     */
    private RelativeLayout Rl_pay;
    private TextView tv_set_pay;
    /**
     * 还款授权
     */
    private RelativeLayout Rl_repayment;
    private TextView tv_set_repayment;

    /**
     * 风险评估
     */
    private RelativeLayout Rl_risk;
    private TextView go_risk_assessment;
    /**
     * 绑卡管理
     */
    private RelativeLayout Rl_card;
    private TextView go_bind_card;
    /**
     * 绑卡弹窗
     **/
    private HSDialog dialog_bindcard = null;
    private HSDialog paypwdDialog = null;
    /**
     * 开户界面
     **/
    private HSDialog dialog_bindname = null;
    private String zwgt_data;
    private boolean ALREADY_AUTHORIZATION;
    private boolean ALREADY_PAY_AUTHORIZATION;
    private int repayment_max_amt;
    private int repayment_min_amt;
    private int repayment_max_deadline;
    private int repayment_min_deadline;

    private int payment_max_amt;
    private int payment_min_amt;
    private int payment_max_deadline;
    private int payment_min_deadline;

    private HSDialog name_dialog; //实名认证dialog
    private boolean isName;
    private HSDialog bindCard_dialog;//绑卡dialog
    private boolean isBindCard;
    private HSDialog psd_dialog;//设置密码dialog
    private HSDialog pay_dialog;
    private boolean isSetPsd;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_management;
    }

    @Override
    protected void initViewsAndEvents() {
        toolbar_title.setTextColor(Color.WHITE);
        toolbar_title.setText("存管信息");
        mToolbar.setNavigationIcon(R.drawable.icon_back);
        mToolbar.setBackgroundColor(Color.parseColor("#FA5B2C"));
        Rl_name = findView(R.id.Rl_name);
        Rl_psd = findView(R.id.Rl_psd);
        Rl_pay = findView(R.id.Rl_pay);
        Rl_repayment = findView(R.id.Rl_repayment);
        Rl_risk = findView(R.id.Rl_risk);
        Rl_card = findView(R.id.Rl_card);

        /**
         *  状态改变
         */
        real_name = findView(R.id.tv_go_name);
        tv_set_psd = findView(R.id.tv_go_psd);
        tv_set_pay = findView(R.id.tv_go_pay);
        tv_set_repayment = findView(R.id.go_repayment);
        go_risk_assessment = findView(R.id.go_risk_assessment);
        go_bind_card = findView(R.id.tv_bind_card);
        /**
         * Onclick
         */
        Rl_name.setOnClickListener(this);
        Rl_psd.setOnClickListener(this);
        Rl_card.setOnClickListener(this);
        Rl_pay.setOnClickListener(this);
        Rl_risk.setOnClickListener(this);
        Rl_repayment.setOnClickListener(this);
        mPresenter = new InitializePresenterImpl(mContext, this);
        initData();


    }

    private void initData() {
        Log.e("Dafdaaf", sharedPreferences.getShareProf(UserInfo.LENDER));
        if (sharedPreferences.getShareProf(UserInfo.LENDER).equals("2")) {
            Rl_risk.setVisibility(View.GONE);
        } else if (sharedPreferences.getShareProf(UserInfo.LENDER).equals("1")) {
            Rl_repayment.setVisibility(View.GONE);
        } else if (sharedPreferences.getShareProf(UserInfo.LENDER).equals("3")) {
            Rl_risk.setVisibility(View.GONE);
            Rl_repayment.setVisibility(View.GONE);
        }
        if (sharedPreferences.getShareProf(UserInfo.IF_BINDCARD).equals("YES")) {
            isBindCard = true;
            go_bind_card.setText("解绑");
        } else {
            isBindCard = false;
            go_bind_card.setText("去绑卡");
        }
        //是否实名
        if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
            //已经开户
            isName = true;
            real_name.setText(getString(R.string.real_name));
        } else {
            //未开户
            isName = false;
            real_name.setText(getString(R.string.go_name));
        }
        //是否设置交易密码
        if (sharedPreferences.getShareProf(UserInfo.IF_PAYPWD).equals("YES")) {
            tv_set_psd.setText("修改");
            isSetPsd = true;
        } else {
            tv_set_psd.setText("去设置");
            isSetPsd = false;
        }
        //是否进行缴费授权
        if (sharedPreferences.getShareProf(UserInfo.IF_PAYPWD).equals("YES")) {
            tv_set_psd.setText("修改");
        } else {
            tv_set_psd.setText("去设置");
        }
        //是否风险评估
        /**
         * 0	未进行风险评估
         1	不通过
         10	保守型
         20	稳健型
         30	平衡型
         40	成长型
         50	进取型/激进型
         */
        String leverStatu = "";
        switch (sharedPreferences.getShareProf(UserInfo.USERLEVEL)) {
            case "10":
                leverStatu = getString(R.string.level10);
                break;
            case "20":
                leverStatu = getString(R.string.level20);
                break;
            case "30":
                leverStatu = getString(R.string.level30);
                break;
            case "40":
                leverStatu = getString(R.string.level40);
                break;
            case "50":
                leverStatu = getString(R.string.level50);
                break;
            case "60":
                leverStatu = getString(R.string.level60);
                break;
            default:
                leverStatu = getString(R.string.level0);
                break;
        }
        go_risk_assessment.setText(leverStatu);
    }

    @Override
    protected void onStart() {
        super.onStart();
        loadingData();
    }


    private void loadingData() {
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        //授权情况
        mPresenter.loadingData(TaskConstants.TASK_GETAUTHLIST, getString(R.string.root_url_test) + getString(R.string.api_user_test) + TaskConstants.TASK_GETAUTHLIST, Constants.EVENT_REFRESH_DATA,
                BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test) + TaskConstants.TASK_GETAUTHLIST, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.
                        getShareProf(UserInfo.TOKENID), zwgt_data), true);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    /**
     * 接受eventBus的回调
     *
     * @param eventCenter
     */
    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {

        switch (eventCenter.getEventCode()) {
            case Constants.EVENT_REFRESH_DATA:
                //刷新登录接口
                mPresenter.initialized();
                break;
        }
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //实名认证
            case R.id.Rl_name:
                if (!NetUtils.isNetworkConnected(mContext)) {
                    showProgressToDismiss();
                    return;
                }
                checkOpenAccountStatus();//验证开户情况
                break;
            //交易密码
            case R.id.Rl_psd:
                if (isNamefun(isName)) {
//                    if (isBindCardfun(isBindCard)) {
                        setPayPwd();
//                    }
                }
                break;
            //缴费授权
            case R.id.Rl_pay:
                if (isNamefun(isName)) {
                    if (isBindCardfun(isBindCard)) {
                        if (isSetPsdfun(isSetPsd)) {
                            if (ALREADY_PAY_AUTHORIZATION) {
                                Bundle bundle = new Bundle();
                                bundle.putString("AUTHORIZATION", Extras.PAYMENT_AUTHORIZATION);
                                readyGoForResult(AuthorizationDetailActivity.class, 0, bundle);
                            } else {
                                Bundle bundle = new Bundle();
                                bundle.putInt(Extras.PAYMENT_MAX_AMT, payment_max_amt);
                                bundle.putInt(Extras.PAYMENT_MIN_AMT, payment_min_amt);
                                bundle.putInt(Extras.PAYMENT_MAX_DEADLINE, payment_max_deadline);
                                bundle.putInt(Extras.PAYMENT_MIN_DEADLINE, payment_min_deadline);
                                readyGoForResult(PayAuthorizationActivity.class, 1, bundle);
                            }
                        }
                    }
                }
                break;
            //还款授权
            case R.id.Rl_repayment:
                if (isNamefun(isName)) {
                    if (isBindCardfun(isBindCard)) {
                        if (isSetPsdfun(isSetPsd)) {
                            if (ALREADY_AUTHORIZATION) {
                                Bundle bundle = new Bundle();
                                bundle.putString("AUTHORIZATION", Extras.REPAYMENT_AUTHORIZATION);
                                readyGoForResult(AuthorizationDetailActivity.class, 0, bundle);
                            } else {
                                Bundle bundle = new Bundle();
                                bundle.putInt(Extras.REPAYMENT_MAX_AMT, repayment_max_amt);
                                bundle.putInt(Extras.REPAYMENT_MIN_AMT, repayment_min_amt);
                                bundle.putInt(Extras.REPAYMENT_MAX_DEADLINE, repayment_max_deadline);
                                bundle.putInt(Extras.REPAYMENT_MIN_DEADLINE, repayment_min_deadline);
                                readyGoForResult(RepaymentAuthorizationActivity.class, 2, bundle);
                            }
                        }
                    }
                }
                break;
            //风险评估
            case R.id.Rl_risk:
                if (isNamefun(isName)) {
                    if (isBindCardfun(isBindCard)) {
                        if (isSetPsdfun(isSetPsd)) {
                            if (!NetUtils.isNetworkConnected(mContext)) {
                                showProgressToDismiss();
                                return;
                            }
                            //level  0 和 1可以点击进入风险评估页面的
                            if (sharedPreferences.contains(mContext, UserInfo.IF_ACCOUNT) && TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
                                if (sharedPreferences.getShareProf(UserInfo.OLD) != null) {
                                    if (sharedPreferences.getShareProf(UserInfo.OLD).isEmpty() || MathUtils.compare(sharedPreferences.getShareProf(UserInfo.OLD), "18") < 0 || MathUtils.compare(sharedPreferences.getShareProf(UserInfo.OLD), "68") >= 0) {
                                        showToast(getString(R.string.age_not_risk));
                                        return;
                                    }
                                }

                                zwgt_data = BaseRequestTool2.getFormatedDateString();
                                HashMap<String, String> hearder = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                                        TaskConstants.TASK_RISKESTIMATE, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                                HeaderMap headerMap = new HeaderMap();
                                headerMap.setMap(hearder);
                                Bundle bundle = new Bundle();
                                bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.risk_estimate));
                                bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_RISKESTIMATE);
                                bundle.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
                                bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                                bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                                readyGo(WebRiskActivity.class, bundle);
                            } else {
                                //未开户
                                showToast(getString(R.string.open_account));
                                readyGo(OpenAccountBankActivity.class);
                            }
                        }
                    }
                }
                break;
            //绑卡管理
            case R.id.Rl_card:
                if (isNamefun(isName)) {
                    if (mConfigSP.contains(mContext, UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS) && !mConfigSP.getBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS)) {
                        showProgressToDismiss();
                        return;
                    }
                    if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
                        //携带银行卡信息
                        readyGo(MineBankCardActivity.class);
                    }
                }
                break;
        }
    }


    /**
     * 根据开户情况进行开户，或者展示开户信息
     */
    public void checkOpenAccountStatus() {
        if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
            String zwgt_data = BaseRequestTool2.getFormatedDateString();
            HashMap<String, String> hearder = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                    TaskConstants.TASK_ACTINFO, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
            HeaderMap headerMap = new HeaderMap();
            headerMap.setMap(hearder);

            Bundle bundle = new Bundle();
            bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.modify_open_account));
            bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_ACTINFO);
            bundle.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
            bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
            bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
            readyGo(WebActivity.class, bundle);
        } else {
            //未开户
            readyGo(OpenAccountBankActivity.class);
        }
    }

    @Override
    public void onItemClick(Object o, int position) {
        if (o == dialog_bindname) {
            if (position != -1) {
                readyGo(OpenAccountBankActivity.class);
            }
        } else if (o == name_dialog && position != -1) {
            if (!NetUtils.isNetworkConnected(mContext)) {
                showProgressToDismiss();
                return;
            }
            checkOpenAccountStatus();//验证开户情况
        } else if (o == bindCard_dialog && position != -1) {
            readyGo(MineBankCardActivity.class);
        } else if (o == psd_dialog && position != -1) {
            setPayPwd();
        } else if (o == pay_dialog && position != -1) {
            Bundle bundle = new Bundle();
            bundle.putInt(Extras.PAYMENT_MAX_AMT, payment_max_amt);
            bundle.putInt(Extras.PAYMENT_MIN_AMT, payment_min_amt);
            bundle.putInt(Extras.PAYMENT_MAX_DEADLINE, payment_max_deadline);
            bundle.putInt(Extras.PAYMENT_MIN_DEADLINE, payment_min_deadline);
            readyGoForResult(PayAuthorizationActivity.class, 1, bundle);

        }
    }

    private void showProgressToDismiss() {
        showProgress("");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                closeProgress();
            }
        }, 2000);
    }


    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.initialized();
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_BANK_ACCOUNT, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_BANK_ACCOUNT, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_BANK_ACCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
    }

    @Override
    public <T> void initializeViews(String task_name, T data) {
        switch (task_name) {
            case TaskConstants.TASK_GETAUTHLIST:
                AuthListBean authListBean = (AuthListBean) data;
                repayment_max_amt = authListBean.repay_auth.rule.max_amt.max;
                repayment_min_amt = authListBean.repay_auth.rule.max_amt.min;
                repayment_max_deadline = authListBean.repay_auth.rule.deadline.max;
                repayment_min_deadline = authListBean.repay_auth.rule.deadline.min;

                payment_max_amt = authListBean.payment_auth.rule.max_amt.max;
                payment_min_amt = authListBean.payment_auth.rule.max_amt.min;
                payment_max_deadline = authListBean.payment_auth.rule.deadline.max;
                payment_min_deadline = authListBean.payment_auth.rule.deadline.min;

                if (authListBean.repay_auth.rst == 0) {
                    ALREADY_AUTHORIZATION = false;
                    tv_set_repayment.setText("去签约");
                } else {
                    ALREADY_AUTHORIZATION = true;
                    tv_set_repayment.setText("去解约");
                }

                if (authListBean.payment_auth.rst == 0) {
                    ALREADY_PAY_AUTHORIZATION = false;
                    tv_set_pay.setText("去签约");
                } else {
                    ALREADY_PAY_AUTHORIZATION = true;
                    tv_set_pay.setText("去解约");
                }

                Rl_pay.setEnabled(true);
                Rl_repayment.setEnabled(true);
                break;
            //设置交易密码回调
            case TaskConstants.TASK_SETBANKPWD:
                if (data == null) {
                    return;
                }
                Log.e("rebankpwd", data.toString());
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        "setbankpwd", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap2 = new HeaderMap();
                headerMap2.setMap(hearder);
                Bundle bundler = new Bundle();
                bundler.putString(BaseWebActivity.BUNDLE_KEY_URL, data.toString());
                bundler.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap2);
                bundler.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
                readyGoThenKill(WebOpenAccountActivity.class, bundler);
                if (BaseAppManager.getInstance().getActivity(MineSettingActivity.class) != null) {
                    BaseAppManager.getInstance().getActivity(MineSettingActivity.class).finish();
                }
                break;
            //重置交易密码回调
            case TaskConstants.TASK_RETBANKRETPWD:
                if (data == null) {
                    return;
                }
                Log.e("rebankpwd", data.toString());
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder0 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        "rebankpwd", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap0 = new HeaderMap();
                headerMap0.setMap(hearder0);
                Bundle bundler0 = new Bundle();
                bundler0.putString(BaseWebActivity.BUNDLE_KEY_URL, data.toString());
                bundler0.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap0);
                bundler0.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
                readyGoThenKill(WebOpenAccountActivity.class, bundler0);
                if (BaseAppManager.getInstance().getActivity(MineSettingActivity.class) != null) {
                    BaseAppManager.getInstance().getActivity(MineSettingActivity.class).finish();
                }
                break;
            case TaskConstants.TASK_CARDBIND:
                Gson gson = new Gson();
                ManeBean maneBean = gson.fromJson(String.valueOf(data), ManeBean.class);
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder1 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        "bindcardpagerst", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap1 = new HeaderMap();
                headerMap1.setMap(hearder1);
                Bundle bundle1 = new Bundle();
                bundle1.putString(BaseWebActivity.BUNDLE_KEY_URL, maneBean.getHtml());
                bundle1.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap1);
                bundle1.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
                readyGo(WebOpenAccountActivity.class, bundle1);
                break;
            //查询托管账户信息，更新ui
            case TaskConstants.TASK_BANK_ACCOUNT:
                BankAccountBeen bankAccountBeen = (BankAccountBeen) data;
                //保存余额信息
//                sharedPreferences.putShareProf(UserInfo.CAN_USE_MONEY, bankAccountBeen.availBal);
                //对江西银行卡信息进行显示
                if (!bankAccountBeen.depository_bank_no.isEmpty()) {//如果返回有银行卡信息，则将银行卡信息保存并且显示银行卡
                    //将获得的银行卡信息保存
                    sharedPreferences.putShareProf(UserInfo.JX_ACCOUNT_NO, bankAccountBeen.depository_bank_no);
                }

                //如果获取了用户的银行卡信息就将其绑定
                /**存储开户信息**/
                if (bankAccountBeen.depository_bank_no != null && !bankAccountBeen.depository_bank_no.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.JIANGXI_BANKCARD, bankAccountBeen.depository_bank_no);
                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
                }

                /**存储绑卡信息**/
                if (bankAccountBeen.bankCard != null && !bankAccountBeen.bankCard.isEmpty() && bankAccountBeen.bankName != null && !bankAccountBeen.bankName.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.BANKCARD, bankAccountBeen.bankCard);
                    sharedPreferences.putShareProf(UserInfo.BANKCARDNAME, bankAccountBeen.bankName);

                    sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "YES");
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "NO");
                }

                if (bankAccountBeen.true_name != null && !bankAccountBeen.true_name.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.REAL_USER_NAME, bankAccountBeen.true_name);
                }

                /**
                 * 绑定身份证
                 */
                if (bankAccountBeen.cert_no != null && !bankAccountBeen.cert_no.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.CERT_NO, bankAccountBeen.cert_no);
                }

                /**保存登陆手机号**/
                //保存手机号码
                if (bankAccountBeen.phone != null && !bankAccountBeen.phone.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.MOBILE, bankAccountBeen.phone);
                }

                /*            *//**保存用户交易密码设置状态**/
                if (bankAccountBeen.set_paypwd_flag != null && !bankAccountBeen.set_paypwd_flag.isEmpty()) {
                    if (TextUtils.equals(bankAccountBeen.set_paypwd_flag, "1")) {
                        //已经设置交易密码
                        sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                    } else {
                        sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                    }
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                }

                /**保存可用余额**/
                if (bankAccountBeen.availBal != null && !bankAccountBeen.availBal.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.CAN_USE_MONEY, bankAccountBeen.availBal);
                }

                //保存用户vip等级
                if (bankAccountBeen.vip != null && !bankAccountBeen.vip.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.VIPLEVEL, bankAccountBeen.vip);
                }
                break;
        }
    }

    /**
     * 设置交易密码
     */
    public void setPayPwd() {
        if (!TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
            showToast(getString(R.string.open_account));
            readyGo(OpenAccountBankActivity.class);
            return;
        }

        if (!TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_BINDCARD), "YES")) {
            showToast(getString(R.string.bind_card_statu));
//            readyGo(BindCardActivity.class);
            if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD), "YES")) {
                bindCar();
            } else {
                //去设置交易密码
                paypwdDialog = new HSDialog(getString(R.string.tips), getString(R.string.tips_nopaypwd),
                        getString(R.string.cancel), getString(R.string.tips_go_set), mContext, this).setCancelable(false);
                paypwdDialog.show();
            }

            return;
        }
        /**
         *  去设置交易密码
         */
        if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD), "NO")) {
            String zwgt_data = BaseRequestTool2.getFormatedDateString();
            JSONObject map1 = new JSONObject();
            JSONObject jsonParams = CommTool.getJSONParams(map1, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
            mPresenter.loadingData(TaskConstants.TASK_SETBANKPWD, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, Constants.EVENT_DATA,
                    jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, sharedPreferences
                            .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
            return;
        }

        //去重置交易密码
        String title = "";
        if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD), "YES")) {
            title = getString(R.string.update2_trading_pass);
            Bundle bundle = new Bundle();
            bundle.putString("title", title);
            if (sharedPreferences.getShareProf(UserInfo.BANKMOBILE) != null) {
                bundle.putString("phone", sharedPreferences.getShareProf(UserInfo.BANKMOBILE));
            }
            String zwgt_data = BaseRequestTool2.getFormatedDateString();
            JSONObject map = new JSONObject();

            JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
            mPresenter.loadingData(TaskConstants.TASK_RETBANKRETPWD, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, Constants.EVENT_DATA,
                    jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, sharedPreferences
                            .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
        }

    }

    private void bindCar() {
        //绑定银行卡
        String zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
        mPresenter.loadingData(TaskConstants.TASK_CARDBIND, getString(R.string.root_url_test) + getString(R.string.api_user_test) + TaskConstants.TASK_CARDBIND,
                Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_user_test) + TaskConstants.TASK_CARDBIND,
                        sharedPreferences.getShareProf(UserInfo.USER_NO),
                        sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
    }

    @Override
    public <T> void initializeError(String task_name, T data) {

    }

    //判断是否实名认证
    private boolean isNamefun(boolean isName) {
        if (isName) {
            return true;
        } else {
            name_dialog = new HSDialog(getString(R.string.tips), "您尚未完成实名认证，请前往实名", "取消",
                    "去实名", mContext, this).setCancelable(false);
            name_dialog.show();
            return false;
        }
    }

    //判断是否绑卡
    private boolean isBindCardfun(boolean isBindCard) {
        if (isBindCard) {
            return true;
        } else {
            bindCard_dialog = new HSDialog(getString(R.string.tips), "您尚未绑定银行卡，请去绑卡", "取消",
                    "去绑卡", mContext, this).setCancelable(false);
            bindCard_dialog.show();
            return false;
        }
    }

    //判断是否设置密码
    private boolean isSetPsdfun(boolean isSetPsd) {
        if (isSetPsd) {
            return true;
        } else {
            psd_dialog = new HSDialog(getString(R.string.tips), "您尚未设置交易密码，请前往设置", "取消",
                    "去设置", mContext, this).setCancelable(false);
            psd_dialog.show();
            return false;
        }
    }

    //判断是否缴费授权
    private boolean isRepay(boolean isSetPsd) {
        if (isSetPsd) {
            return true;
        } else {
            pay_dialog = new HSDialog(getString(R.string.tips), "您尚未进行缴费授权，请先签订缴费授权", "暂不签约",
                    "立即签约", mContext, this).setCancelable(false);
            pay_dialog.show();
            return false;
        }
    }
}
